//外贸基础表的crud

import axios from "axios";
import {ElMessage} from "element-plus";

//添加外贸基础数据
export async function saveForeignBase(data){
    try {
        const response = await axios.post('http://localhost:8888/foreign_base/save',data)
        if (response.data.code === '00000'){
            ElMessage.success('添加成功!')
        }else {
            ElMessage.error(response.data.message)
        }
    }catch (e) {
        ElMessage.error(e)
        console.log(e)
    }
}

//修改外贸基础数据
export async function modifyForeignBase(data){
    try {
        const response = await axios.post('http://localhost:8888/foreign_base/modify',data)
        if (response.data.code === '00000'){
            ElMessage.success('修改成功!')
        }else {
            ElMessage.error(response.data.message)
        }
    }catch (e) {
        ElMessage.error(e)
        console.log(e)
    }
}

//删除外贸基础数据
export async function removeForeignBase(data){
    try {
        const response = await axios.post('http://localhost:8888/foreign_base/remove_by_fba',data)
        if (response.data.code === '00000'){
            ElMessage.success(`删除${data.fbaCode}成功!`)
        }else {
            ElMessage.error(response.data.message)
        }
    }catch (e) {
        ElMessage.error(e)
        console.log(e)
    }
}

//确认货代后保存货代id
export async function saveForwarderId(data){
    try {
        const response = await axios.post('http://localhost:8888/foreign_base/save_forwarder_id',data)
        if (response.data.code === '00000'){
            ElMessage.success(`${data.fbaCode}选择了货代id:${data.forwarderId}`)
        }else {
            ElMessage.error(response.data.message)
        }
    }catch (e) {
        ElMessage.error(e)
        console.log(e)
    }
}